package com.leyou.auth.local;


import com.leyou.auth.dto.UserDetails;

public class UserContext {

    private final static ThreadLocal<UserDetails> tl = new ThreadLocal();
    private final static ThreadLocal<String> jwtTl = new ThreadLocal();

    public static void setJwtTl(String jwt){
        jwtTl.set(jwt);
    }

    public static String getJwt(){
        return jwtTl.get();
    }

    public static void removeJwt() {
        removeJwt();
    }
    /**
     * 向threadLocal添加数据
     * @param user      用户对象
     */
    public static void setUser(UserDetails user) {
        tl.set(user);
    }

    /**
     * 从threadLocal中获取数据
     * @return
     */
    public static UserDetails getUser() {
        return tl.get();
    }

    /**
     * 从threadLocal中移除数据
     */
    public static void removeUser() {
        tl.remove();
    }
}
